package cn.zyzpp.service.resume.impl;

import cn.zyzpp.dao.WorksShowDao;
import cn.zyzpp.entity.resume.WorksShow;
import cn.zyzpp.service.resume.WorksShowService;
import cn.zyzpp.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Create by yster@foxmail.com 2018/5/21/021 23:03
 */
@Service
@CacheConfig(cacheNames = {"WorksShowService"})
public class WorksShowImpl implements WorksShowService {
    @Autowired
    private WorksShowDao worksShowDao;

    @Override
    @CacheEvict(allEntries = true)
    public void save(WorksShow worksShow, int uid) {
        worksShow.setUid(uid);
        worksShow.setW_explain(StringUtil.symline(worksShow.getW_explain()));
        worksShowDao.save(worksShow);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void delect(int id) {
        worksShowDao.deleteAllById(id);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void updataByUid(WorksShow worksShow) {
        WorksShow worksShow1 = worksShowDao.findByUid(worksShow.getUid());
        worksShow.setW_explain(StringUtil.symline(worksShow.getW_explain()));
        worksShow1.updata(worksShow);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public List<WorksShow> queryAll(int uid) {
        return worksShowDao.findAllByUid(uid);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public WorksShow query(int uid) {
        return worksShowDao.findByUid(uid);
    }
}
